package cn.xy.base.server.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.xy.base.server.enums.PermissionType;
import cn.xy.base.server.po.SysPermission;
import cn.xy.commons.enums.YesNoStatus;
import cn.xy.commons.validator.EnumValidator;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;

/**
 * 表[sys_permission]对应UpdateDTO类
 *
 * @author auto
 */

@Data
public class SysPermissionUpdateDTO {

    /**
     * 自增id
     */
    @Min(value = 1, message = "ID不能为空")
    @ApiModelProperty(value = "自增id", dataType = "Integer")
    private Integer id;

    /**
     * 父权限ID，一级菜单为0
     */
    @ApiModelProperty(value = "父权限ID，一级菜单为0", dataType = "int")
    private int parentId;

    /**
     * 类别，1目录，2菜单，3权限
     */
    @EnumValidator(clazz = PermissionType.class, message = "请选择类别")
    @ApiModelProperty(value = "类别，1目录，2菜单，3权限", dataType = "int")
    private int type;

    /**
     * layout: default、full
     */
    @ApiModelProperty(value = "layout: default、full", dataType = "String")
    private String layout;

    /**
     * 权限/菜单名称
     */
    @NotEmpty(message = "名称不能为空")
    @ApiModelProperty(value = "权限/菜单名称", dataType = "String")
    private String title;

    /**
     * 组件名
     */
    @ApiModelProperty(value = "组件名", dataType = "String")
    private String component;

    /**
     * 标识名
     */
    @NotEmpty(message = "key不能为空")
    @ApiModelProperty(value = "标识名", dataType = "String")
    private String key;

    /**
     * 访问路径
     */
    @ApiModelProperty(value = "访问路径", dataType = "String")
    private String path;

    /**
     * 默认跳转
     */
    @ApiModelProperty(value = "默认跳转", dataType = "String")
    private String redirect;

    /**
     * 权限图标，菜单用
     */
    @ApiModelProperty(value = "权限图标，菜单用", dataType = "String")
    private String icon;

    /**
     * 排序权重
     */
    @Min(value = 0, message = "排序权重最小为0")
    @Max(value = 9999, message = "排序权重最大为9999")
    @ApiModelProperty(value = "排序权重（0-9999）", dataType = "int")
    private int sort;

    /**
     * 是否隐藏,Y隐藏，N显示
     */
    @NotEmpty(message = "请选择是否隐藏")
    @EnumValidator(clazz = YesNoStatus.class, message = "请选择是否隐藏")
    @ApiModelProperty(value = "是否隐藏,Y隐藏，N显示", dataType = "String")
    private String hidden;

    public SysPermission toSysPermission() {
        SysPermission sysPermission = new SysPermission();
        BeanUtil.copyProperties(this, sysPermission);
        return sysPermission;
    }
}
